package com.soft.base.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.util.Date;
/**
 * class
 *
 * @author user
 * @date 2020/06/05
 */
public class TimeFillMetaObjectHandler implements MetaObjectHandler {

    private final String INSERT_FIELD = "createdAt";
    private final String UPDATE_FIELD = "updatedAt";

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName(INSERT_FIELD, new Date(), metaObject);
        this.setFieldValByName(UPDATE_FIELD, new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName(UPDATE_FIELD, new Date(), metaObject);
    }
}
